﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using SaiLing.Domain.Specification;
using SaiLing.SingleSignOn.Domain.Entities.System;

namespace SaiLing.SingleSignOn.Domain.Specifications.System
{
    public class ApplicationSpecification : ISpecification<Application>
    {
        private string Name { get; set; }

        private string AppKey { get; set; }

        public ApplicationSpecification(string name, string appkey)
        {
            Name = name;
            AppKey = appkey;
        }

        public Expression<Func<Application, bool>> SatisfiedBy()
        {
            Specification<Application> spec = new TrueSpecification<Application>();
            spec &= new DirectSpecification<Application>(x => !x.LogicRemove);
            if (!string.IsNullOrWhiteSpace(Name))
                spec &= new DirectSpecification<Application>(x => x.Name.Contains(Name));
            if (!string.IsNullOrWhiteSpace(AppKey))
                spec &= new DirectSpecification<Application>(x => x.AppKey == (AppKey));
            return spec.SatisfiedBy();
        }
    }
}
